import axios from 'axios';

export default {
   namespaced: true,
   state: {
      shopData: [
         {
            _id: "fbgd5b1g51b31g32b1g32b",
            name: "name",       // 名称
            address: "address",    // 地址
            telephone: "telephone",  // 电话
            desc: "desc",       // 门店描述
            adminsId: "adminsId",
         }
      ],
      dataPage: {
         currentPage: 1,
         pageSize: 5,
         toatlPage: 1,
         totalCount: 1
      },
   },
   mutations: {
      ///   修改每页几条数据
      setpageSize(state, data) {
         state.dataPage.pageSize = data;
      },

      ///   修改当前页
      setcurrentPage(state, data) {
         state.dataPage.currentPage = data;
      },

      render(state, data) {
         state.shopData = data.shopData;
         state.dataPage = data.datapage;
      }
   },
   actions: {
      //    新增
      addShop(state, data) {
         data.adminsId = JSON.parse(localStorage.usertoken1)._id;
         axios.post("/api/shopManage/add", data).then(res => { console.log(res.data) });
      },
      //    查询
      findShop(state, data = {}) {
         axios.post("/api/shopManage/find", data).then(res => {
            state.commit("render", res.data);
         });
      },
      //    删除
      remove(state, data) {
         axios.post("/api/shopManage/remove", data)
      },
      //    修改
      setShop(state, data) {
         axios.post("/api/shopManage/set", data)
      }
   }
}